package com.huabo.contract.service.impl;

import com.hbfk.util.PageInfo;
import com.huabo.contract.config.DateBaseConfig;
import com.huabo.contract.oracle.entity.TblLegalProceedingsrecord;
import com.huabo.contract.oracle.mapper.TblLegalDisputregistrationMapper;
import com.huabo.contract.oracle.mapper.TblLegalProceedingsrecordMapper;
import com.huabo.contract.service.TblLegalProceedingsrecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TblLegalProceedingsrecordServiceImpl implements TblLegalProceedingsrecordService {

    @Resource
    private TblLegalProceedingsrecordMapper tblLegalProceedingsrecordMapper;

    @Resource
    private TblLegalDisputregistrationMapper tblLegalDisputregistrationMapper;
    @Override
    public void saveProceedingRecord(TblLegalProceedingsrecord proceed) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalProceedingsrecordMapper.saveProceedingRecord(proceed);
        } else {
            this.tblLegalProceedingsrecordMapper.saveProceedingRecord(proceed);
        }
    }

    @Override
    public TblLegalProceedingsrecord findById(Integer proceedid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return tblLegalProceedingsrecordMapper.findByProceedid(proceedid);
        } else {
            return tblLegalProceedingsrecordMapper.findByProceedid(proceedid);
        }
    }

    @Override
    public void modifyNegotiateRecord(TblLegalProceedingsrecord oldproceed) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalProceedingsrecordMapper.updateModifyNegotiateRecord(oldproceed);
        } else {
            this.tblLegalProceedingsrecordMapper.updateModifyNegotiateRecord(oldproceed);
        }
    }

    @Override
    public void removeNegitiateRecord(Integer proceedId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            this.tblLegalProceedingsrecordMapper.deleteProceedid(proceedId);
        } else {
            this.tblLegalProceedingsrecordMapper.deleteProceedid(proceedId);
        }
    }

    @Override
    public List<TblLegalProceedingsrecord> findListByLitigationid(Integer litigationid) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            return this.tblLegalProceedingsrecordMapper.findListByLitigationid(litigationid);
        } else {
            return this.tblLegalProceedingsrecordMapper.findListByLitigationid(litigationid);
        }
    }


    @Override
    public void findListByPageInfo(PageInfo<TblLegalProceedingsrecord> pageInfo, TblLegalProceedingsrecord record) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            pageInfo.setTlist(tblLegalProceedingsrecordMapper.findListByPageInfo(pageInfo, record));
            pageInfo.setTotalRecord(tblLegalProceedingsrecordMapper.findListByPageInfoCount(record));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);

            pageInfo.setTlist(tblLegalProceedingsrecordMapper.findListByPageInfo(pageInfo, record));
            pageInfo.setTotalRecord(tblLegalProceedingsrecordMapper.findListByPageInfoCount(record));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }

    @Override
    public void findByNegotiaId(PageInfo<TblLegalProceedingsrecord> pageInfo, Integer litigationId) {
        if(DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalProceedingsrecordMapper.findByNegotiaId(pageInfo, litigationId));
            pageInfo.setTotalRecord(tblLegalProceedingsrecordMapper.findByNegotiaIdCount(litigationId));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            pageInfo.setTlist(tblLegalProceedingsrecordMapper.findByNegotiaId(pageInfo, litigationId));
            pageInfo.setTotalRecord(tblLegalProceedingsrecordMapper.findByNegotiaIdCount(litigationId));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("date", pageInfo);
        }
    }
}
